<script setup>
import {ref} from "vue";
import axios from "axios";
import {useRouter} from "vue-router";
import { ElMessage } from 'element-plus'
const form = ref({
  username: null,
  password: null
})
let router = useRouter();
const onSubmit=async () => {
  // console.log(form.value)
  const res = await axios({
    url: "http://localhost:8081/user/login",
    method: 'post',
    data: {
      username: form.value.username,
      password: form.value.password
    },
    withCredentials: true
  })

  // console.log(res.data.flag)
  if(res.data.flag){
    router.push("/main")
    ElMessage.success("登录成功")
  }else{
    ElMessage.error("登录失败")
  }
}
</script>

<template>
  <el-row>
    <el-col :span="12" :offset="6">
      <el-form :model="form">
        <el-form-item>
          <h1>登录</h1>
        </el-form-item>
        <el-form-item>
          <el-input placeholder="请输入用户名" v-model="form.username"></el-input>
        </el-form-item>
        <el-form-item>
          <el-input placeholder="请输入密码" v-model="form.password"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="onSubmit">登录</el-button>
        </el-form-item>
      </el-form>
    </el-col>
  </el-row>
</template>

<style scoped>

</style>